package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectNumberHashMap;
import org.farng.mp3.object.ObjectStringNullTerminated;
import org.farng.mp3.object.ObjectStringSizeTerminated;

import java.io.IOException;


/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyWXXX extends AbstractID3v2FrameBody {
    /** DOCUMENT ME! */
    String description = "";

    /** DOCUMENT ME! */
    String urlLink = "";

    /** DOCUMENT ME! */
    byte textEncoding = 0;

    /**
     * Creates a new FrameBodyWXXX object.
     */
    public FrameBodyWXXX() {
        //        this.setObject("Text Encoding", new Byte((byte) 0));
        //        this.setObject("Description", "");
        //        this.setObject("URL", "");
    }

    public FrameBodyWXXX(FrameBodyWXXX body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyWXXX object.
     *
     * @param textEncoding DOCUMENT ME!
     * @param description DOCUMENT ME!
     * @param urlLink DOCUMENT ME!
     */
    public FrameBodyWXXX(byte textEncoding, String description, String urlLink) {
        this.setObject("Text Encoding", new Byte(textEncoding));
        this.setObject("Description", description);
        this.setObject("URL", urlLink);
    }

    /**
     * Creates a new FrameBodyWXXX object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyWXXX(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getBriefDescription() {
        return this.getUrlLink();
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "WXXX" + ((char) 0) + description;
    }

    /**
     * DOCUMENT ME!
     *
     * @param urlLink DOCUMENT ME!
     */
    public void setUrlLink(String urlLink) {
        setObject("URL", urlLink);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getUrlLink() {
        return (String) getObject("URL");
    }

    /**
     * DOCUMENT ME!
     *
     * @param obj DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public boolean equals(Object obj) {
        if ((obj instanceof FrameBodyWXXX) == false) {
            return false;
        }

        FrameBodyWXXX object = (FrameBodyWXXX) obj;

        if (this.description.equals(object.description) == false) {
            return false;
        }

        if (this.textEncoding != object.textEncoding) {
            return false;
        }

        if (this.urlLink.equals(object.urlLink) == false) {
            return false;
        }

        return super.equals(obj);
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberHashMap("Text Encoding", 1));
        objectList.add(new ObjectStringNullTerminated("Description"));
        objectList.add(new ObjectStringSizeTerminated("URL"));
    }
}